﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wpf3D.WcfServiceDuplex;
using System.ServiceModel;
namespace Wpf3D
{
    /// <summary>
    /// Interaction logic for DuplexWindow.xaml
    /// </summary>
    public partial class DuplexWindow : Window
    {
        CalculatorDuplexClient sc;
        public DuplexWindow()
        {
            InitializeComponent();
            InstanceContext inContext = new InstanceContext(new CallbackHandler(this.textBlock1, this.textBlock2));
             sc = new CalculatorDuplexClient(inContext, "NetTcpBinding_ICalculatorDuplex");
            double value = 100.00D;
            sc.AddTo(value);
            value = 50.00D;
            sc.SubtractFrom(value);
            value = 10.00D;
            sc.MultiplyBy(value);
            value = 2.00D;
            sc.DivideBy(value);
           
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            double value = 200.00D;
            sc.AddTo(value);
            value = 50.00D;
            sc.SubtractFrom(value);
            value = 10.00D;
            sc.MultiplyBy(value);
            value = 2.00D;
            sc.DivideBy(value);
            sc.Clear();
        }
       
    }

    public class CallbackHandler : ICalculatorDuplexCallback
    {
        public CallbackHandler(object obj, object obj1)
        {
            this.Obj = obj;
            this.Obj1 = obj1;
        }

        public object Obj { get; set; }
        public object Obj1 { get; set; }


        public void Equals(double result)
        {
            ((TextBlock)Obj).Text += result.ToString() + " | | ";
        }

        public void Equation(string eqn)
        {
            ((TextBlock)Obj1).Text = eqn;
        }
    }
}
